package edu.cmu.ibill.model;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

/**
 * 
 */
public class Model {
	private UserDAO userDAO;
	private DebtDAO debtDAO;
	private PersonalBillDAO personalbillDAO;
	private CategoryDictDAO categorydictDAO;

	public Model(ServletConfig config) throws ServletException {
		try {
			String csvDirStr = config.getInitParameter("csvDir");
			if (csvDirStr != null && csvDirStr.length() > 0) {
				// File csvDir = new File(csvDirStr);
			} else {
				String jdbcDriver = config.getInitParameter("jdbcDriverName");
				String jdbcURL = config.getInitParameter("jdbcURL");
				String jdbcUser = config.getInitParameter("jdbcUser");
				String jdbcPassword = config.getInitParameter("jdbcPassword");

				userDAO = new UserDAO(jdbcDriver, jdbcURL, jdbcUser,
						jdbcPassword);

				debtDAO = new DebtDAO(jdbcDriver, jdbcURL, jdbcUser,
						jdbcPassword);

				personalbillDAO = new PersonalBillDAO(jdbcDriver, jdbcURL,
						jdbcUser, jdbcPassword);

				categorydictDAO = new CategoryDictDAO(jdbcDriver, jdbcURL,
						jdbcUser, jdbcPassword);

			}

		} catch (Exception e) {
			throw new ServletException(e);
		}
	}

	public UserDAO getUserDAO() {
		return userDAO;
	}

	public DebtDAO getDebtDAO() {
		return debtDAO;
	}

	public PersonalBillDAO getPersonalBillDAO() {
		return personalbillDAO;
	}
	
	public CategoryDictDAO getCategoryDictDAO(){
		return categorydictDAO;
	}
}
